home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 8434 / 8434.xpi / chrome / content / update.js < prev    next >
Text File  |  2008-11-16  |  4KB  |  127 lines

  1. var stylesToUpdate = [];
  2. var enumerator, progress, styleCount, style, list, strings;
  3. var numberDone = 0;
  4. function init() {
  5.     list = document.getElementById("style-list");
  6.     styleCount = GoogleRedesignedStyle.prototype.ds.getNode(GoogleRedesignedStyle.prototype.containerURI).getChildCount();
  7.     enumerator = GoogleRedesignedStyle.prototype.ds.getNode(GoogleRedesignedStyle.prototype.containerURI).getChildren();
  8.     progress = document.getElementById("progress");
  9.     strings = document.getElementById("strings");
  10.     checkNext();
  11. }
  12. function updateAll() {
  13.     document.getElementById("update-all").setAttribute("disabled", "true");
  14.     update(stylesToUpdate);
  15.     stylesToUpdate = [];
  16.     GoogleRedesignedStyle.prototype.ds.save();
  17. }
  18. function update(styles) {
  19.     progress.style.display = "";
  20.     for (var i = 0; i < styles.length; i++) {
  21.         var originallyEnabled = styles[i].enabled;
  22.         if (originallyEnabled) {
  23.             styles[i].enabled = false;
  24.         }
  25.         styles[i].code = styles[i].updatedCode;
  26.         styles[i].originalCode = styles[i].updatedCode;
  27.         styles[i].customized = false;
  28.         if (originallyEnabled) {
  29.             styles[i].enabled = true;
  30.         }
  31.         list.removeChild(document.getElementById(styles[i].uri));
  32.         progress.setAttribute("value", (0 + i) / styles.length * 100 + "%");
  33.     }
  34.     progress.style.display = "none";
  35.     progress.setAttribute("value", "0%");
  36. }
  37. function neverUpdate(styles) {
  38.     for (var i = 0; i < styles.length; i++) {
  39.         styles[i].neverUpdate = true;
  40.         list.removeChild(document.getElementById(styles[i].uri));
  41.     }
  42. }
  43. function checkNext() {
  44.     if (enumerator.hasMoreElements()) {
  45.         style = new GoogleRedesignedStyle(enumerator.getNext());
  46.         style.checkForUpdate(updateCheckDone);
  47.     } else {
  48.         progress.style.display = "none";
  49.         progress.setAttribute("value", "0%");
  50.         document.getElementById("style-list-tree").setAttribute("disabled", "false");
  51.         if (stylesToUpdate.length > 0) {
  52.             document.getElementById("update-all").setAttribute("disabled", "false");
  53.         }
  54.     }
  55. }
  56. function updateCheckDone(updatedCode) {
  57.     if (updatedCode) {
  58.         style.updatedCode = updatedCode;
  59.         var item = document.createElementNS(googleredesignedCommon.XULNS, "treeitem");
  60.         item.setAttribute("id", style.uri);
  61.         var row = document.createElementNS(googleredesignedCommon.XULNS, "treerow");
  62.         var uriCell = document.createElementNS(googleredesignedCommon.XULNS, "treecell");
  63.         uriCell.setAttribute("label", style.uri);
  64.         var descriptionCell = document.createElementNS(googleredesignedCommon.XULNS, "treecell");
  65.         descriptionCell.setAttribute("label", style.description);
  66.         var customizedCell = document.createElementNS(googleredesignedCommon.XULNS, "treecell");
  67.         customizedCell.setAttribute("label", style.customized ? strings.getString("yes") : strings.getString("no"));
  68.         customizedCell.setAttribute("class", "customized-column");
  69.         row.appendChild(uriCell);
  70.         row.appendChild(descriptionCell);
  71.         row.appendChild(customizedCell);
  72.         item.appendChild(row);
  73.         list.appendChild(item);
  74.         stylesToUpdate.push(style);
  75.     }
  76.     numberDone++;
  77.     progress.setAttribute("value", (0 + numberDone) / styleCount * 100 + "%");
  78.     checkNext();
  79. }
  80. function updateSelected(never) {
  81.     var indices = getSelectedIndices();
  82.     var styles = [];
  83.     for (var i = 0; i < indices.length; i++) {
  84.         styles.push(stylesToUpdate[indices[i]]);
  85.     }
  86.     var stylesNotUpdated = [];
  87.     for (var i = 0; i < stylesToUpdate.length; i++) {
  88.         var found = false;
  89.         for (var j = 0; j < indices.length; j++) {
  90.             if (i == indices[j]) {
  91.                 found = true;
  92.                 break;
  93.             }
  94.         }
  95.         if (!found) {
  96.             stylesNotUpdated.push(stylesToUpdate[i]);
  97.         }
  98.     }
  99.     if (never) {
  100.         neverUpdate(styles);
  101.     } else {
  102.         update(styles);
  103.     }
  104.     stylesToUpdate = stylesNotUpdated;
  105.     if (stylesToUpdate.length == 0) {
  106.         document.getElementById("update-all").setAttribute("disabled", "true");
  107.     }
  108.     GoogleRedesignedStyle.prototype.ds.save();
  109. }
  110. function getSelectedIndices() {
  111.     var indices = [];
  112.     var rangeCount = list.parentNode.view.selection.getRangeCount();
  113.     for (var i = 0; i < rangeCount; i++) {
  114.         var start = {};
  115.         var end = {};
  116.         list.parentNode.view.selection.getRangeAt(i, start, end);
  117.         for (var c = start.value; c <= end.value; c++) {
  118.             indices.push(c);
  119.         }
  120.     }
  121.     return indices;
  122. }
  123. function changeSelection() {
  124.     document.getElementById("update-selected").setAttribute("disabled", getSelectedIndices().length == 0 ? "true" : "false");
  125.     document.getElementById("never-update-selected").setAttribute("disabled", getSelectedIndices().length == 0 ? "true" : "false");
  126. }
  127.